package com.atjava.nebula.core.exception.support;

import com.atjava.nebula.core.exception.handler.IExceptionHandler;
import com.atjava.nebula.core.exception.handler.impl.FileLogExceptionHandler;

/**
 * 工厂创建具体IExceptionHandler的实现类
 */
public class ExpHandlerFactory {

	//public static final String EXCEPTION_HANDLER_KEY = "AppExceptionHandler";
	private static IExceptionHandler iexHandler;
	static{
		iexHandler=new FileLogExceptionHandler();
	}
	
	public static IExceptionHandler getInstance() {
		return iexHandler;
		//return (IExceptionHandler)SpringBeanFactory.getBean(EXCEPTION_HANDLER_KEY);
	}
	
	public static IExceptionHandler getInstance(String exceptionHandlerType) {
		if (exceptionHandlerType != null) {
			try {
				return (IExceptionHandler) Class.forName(exceptionHandlerType).newInstance() ;
			} catch (Exception e) {
				ExceptionUtil.logException(ExpHandlerFactory.class, e, null) ;
				e.printStackTrace() ;
			} 
		}
		return null;
	}
}